function Result() {
	var that;
}

Result.prototype = {
	aud:'',
	audA:'',
	result:'',
	statistic_url:'/tug/screen/statistic',
	init:function() {
		that = this;
		that.meet_id = that.getQueryString("meet_id");
		that.sequence = that.getQueryString("sequence");
		that.round = that.getQueryString("sequence");
		that.aud = document.getElementById("aud");
		that.audA = document.getElementById("audA");
		//获取游戏结果
		that.getResult();
	},
	getResult:function(){
		var resultInfo = JSON.parse(that.getItems('resultInfo'));
		console.log(resultInfo);
		that.statistic(resultInfo);
	},
	statistic:function(ret) {
			 var result = ret.gameStatusInfo.win;
			 var redInfo = ret.redTeamInfo;
			 var blueInfo = ret.blueTeamInfo;
			 var gameInfo =ret.gameStatusInfo;
			 var winTeamUsers = ret.winTeamUsers;
			// win 红队赢
			if(result == 1) {
				$("#win").find(".name").html(redInfo.team_name);
				$("#win").find(".name").addClass("red");
				$("#win").find(".team-img").attr("src",redInfo.team_image);
				$("#win").find(".power").html("总力量："+ gameInfo.red_score);

				$("#fail").find(".name").html(blueInfo.team_name);
				$("#fail").find(".name").addClass("blue");
				$("#fail").find(".team-img").attr("src",blueInfo.team_image);
				$("#fail").find(".power").html("总力量："+ gameInfo.blue_score);
				$("#fail").find(".teamImg-group").addClass("blue");

				$("#win-teamImg-group").addClass("red");
				$("#win_name").html(redInfo.team_name+"获胜");
				$("#win-teamImg-group").find("img").attr("src",redInfo.team_image);
				that.fillDataSlider(winTeamUsers);
				that.startSlider(1);
			}
			// 蓝队赢
			if(result == 2 ) {
				$("#win").find(".name").html(blueInfo.team_name);
				$("#win").find(".team-img").attr("src",blueInfo.team_image);
				$("#win").find(".power").html("总力量："+gameInfo.blue_score);
				$("#win").find(".teamImg-group").addClass("blue");

				$("#fail").find(".name").html(redInfo.team_name);
				$("#fail").find(".team-img").attr("src",redInfo.team_image);
				$("#fail").find(".power").html("总力量："+gameInfo.red_score);

				$("#win-teamImg-group").addClass("blue");
				$("#win_name").html(blueInfo.team_name+"获胜");
				$("#win-teamImg-group").find("img").attr("src",blueInfo.team_image);
				that.fillDataSlider(winTeamUsers);
				that.startSlider(1);
			}
			//equal 平局
			if(result == 0 ) {
				$("#win").find(".name").html(blueInfo.team_name);
				$("#win").find(".team-img").attr("src",blueInfo.team_image);
				$("#win").find(".power").html("总力量："+ gameInfo.blue_score);
				$("#win").find(".teamImg-group").addClass("blue");

				$("#fail").find(".name").html(redInfo.team_name);
				$("#fail").find(".team-img").attr("src",redInfo.team_image);
				$("#fail").find(".power").html("总力量："+gameInfo.red_score);

				$("#fail,#win").find(".sign").hide();
				$("#equal").show();
				that.startSlider(0);
			}
	},

	fillDataSlider:function(data) {
		var obj = $("#swiper-container").children(".swiper-wrapper");
		var i = 0,j = 0,json,html = [];
		for(var key in data) {
			json = data[key];
			j = i++;
			if( !(j % 20) ){
				html.push('<li class="clearfix slider-item swiper-slide">');
			}
			html.push('<div class="fl">');
			html.push('<div>');
			html.push('<img src="'+json.headimgurl.replace("/0","/46")+'" class="responseImg" alt="" title="" />');
			html.push('</div>');
			html.push('<p class="nickname textset">'+json.nickname+'</p>');
			html.push('</div>');
			if(!(++j % 20) && j >= 20) {
				html.push("</li>");
			}
		}
		if(!/(^[0-9]\d*$)/.test(i/20)) {
			html.push("</li>");
		}
		obj.html(html.join(''));
	},
	// flag: 0:平局  1: 胜负
	startSlider:function(flag) {
		var timerA = setTimeout(function() {
				$("#fail,#win").css("marginTop","16px");
				clearTimeout(timerA);
		}, 1000);
		if(flag == 0) {
			that.playMusic(0,that.aud);
		}
		if(flag == 1){
			var timerB = setTimeout(function() {
					that.playMusic(1,that.aud);
					$("#ko").removeClass("default-ko");
					clearTimeout(timerB);
			}, 2000);
			var timerC = setTimeout(function() {
					$("#ko").addClass("default-ko");
					$("#section1").css("height","0");
					that.playMusic(2,that.audA);
					clearTimeout(timerC);
			}, 8000);
			var swiper = new Swiper('#swiper-container', {
			    pagination: '.swiper-pagination',
			    paginationClickable: true,
			    spaceBetween: 30,
			    autoplay:2000,
			    loop:true
			});
		}

	},
	//status 0:平局  1: 胜负
	playMusic:function(status,obj) {
		if(status == 0) {
			obj.src = '/music/kiss.mp3';
		}
		if(status == 1) {
			obj.src = '/music/ko.mp3';
		}
		//播放背景乐
		if(status == 2) {
			obj.src = '/music/presentation.mp3';
		}
		obj.play();
	},
	_gameAgain:function() {
		window.location.href = '/tug/screen/game' + window.location.search;
	},
	setItems:function(key,value) {
		sessionStorage.setItem(key,value);
	},
	getItems:function(key) {
		return sessionStorage.getItem(key);
	},
	request_data:function(url,data,callback,errorCallback) {
		$.ajax({
			type:"post",
			url:url,
			dataType:"json",
			data:data,
			async: false,
			success:function(ret) {
				callback && callback(ret);
			},
			error:function() {
				errorCallback && errorCallback();
			}
		})
	},
	getQueryString:function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]); return null;
	}
}
